<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Symbol iterator</title>
</head>

<body>
  <script>
    class Emitter {
      constructor(max) {
        this.max = max;
        this.idx = 0
      }
      *[Symbol.iterator]() {
        while (this.idx < this.max) {
          yield this.idx++;
        }
      }
    }
    function count() {
      let emitter = new Emitter(5)
      for (const value of emitter) {
        console.log(value)
      }
    }
    count()
  </script>
</body>

</html>